<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="vtc" uri="/ls-trade-tags"%>
<%@ include file="/common/taglibs.jsp"%>
<html>
<head>
	<title>1st Level Planning</title>
</head>
<body>

<script type="text/javascript">
	$(document).ready(function() {
		$("#mainForm").validate();
	});

	function onPlanYearChange(planYear,clickedField) {
		
		$("#level1Planning_planningExercise").val(planYear);
		
		if(clickedField=="plan-year"){
			$.ajax({
				url : "plan-first!ajaxPlanningExerciseTemList.action?level1Planning.planningExercise="+planYear,
				cache : true,
				dataType : "json",
				async : false,
				success : function(paramObjList) {
					$("#planningExerciseTem").empty();
					
					$.each(paramObjList, function(i, paramObject) {
						$("#planningExerciseTem").append(
								"<option value='"+paramObject.code+"'>" + paramObject.desc + "</option>");
					})
				},
				error : function(data) {
					$("#errorMsgSpan").html(data);
				}
			});				
		}		
		
			
		$.ajax({
			url : "plan-first!ajaxCategoryList.action?level1Planning.planningExercise="+planYear+"&operator="+$("#operator").val(),
			cache : true,
			dataType : "json",
			async : false,
			success : function(data) {
				$("#level1PlanningCategory").empty();
				$("#level1PlanningCategory").append("<option value=''>- Select -</option>");
				$.each(data, function(i, n) {
					$("#level1PlanningCategory").append(
							"<option value='"+n.code+"'>" + n.desc + "</option>");
				})
			},
			error : function(data) {
				$("#errorMsgSpan").html(data);
			}
		});
	}
	
	function clickBtn(action,level1PlanningId){
		switch(action){
		case "create":
			window.location="plan-first!input.action?operator="+$("#operator").val();
			return;
		case "clear":
			$("#mainForm").attr("action","plan-first.action?clear=true");
			break;
		case "search":
			$("#mainForm").attr("action","plan-first.action?search=true");
			break;	
			
		case "delete":
			$("#mainForm").attr("action","plan-first!delete.action?level1PlanningId="+level1PlanningId);
			break;	
			
		case "edit":
			window.location="plan-first!input.action?level1PlanningId="+level1PlanningId+"&operator="+$("#operator").val();
			return;				
		}
		
		$("#mainForm").submit();
	}
</script>

<div class="content"> 
<div class="pageTitle">1st Level Planning </div>
<s:form id="mainForm" name="mainForm" action="plan-first.action" method="post">
  <s:hidden name="level1Planning.planningExercise" id="level1Planning_planningExercise"></s:hidden>
  <s:hidden name="search"></s:hidden>
  <div class="form1">
  
  <table cellspacing="0" cellpadding="0" border="0">
    <tbody>
    <tr>
      <td width="155px"><label class="fLabel">Planning Exercise</label>
        <div class="fField">
            <s:select cssStyle="width:150px" name="planYearTem" id="planYearTem" 
            		  list="slashYearList" listKey="code" listValue="desc" onchange="onPlanYearChange(this.value,'plan-year')"
            		  headerKey="" headerValue="-- Select --">
            </s:select>
        </div>
      </td>
      
      <td width="255px"><label class="fLabel">Planning Exercise Name</label>
        <div class="fField">
            <s:select cssStyle="width:250px" name="planningExerciseTem" id="planningExerciseTem" 
            		  list="planningExerciseTemList" listKey="code" listValue="desc" onchange="onPlanYearChange(this.value)"
            		  >
            </s:select>
        </div>
      </td>
      
      <td><label class="fLabel">Owner Or Planner</label>
        <div class="fField">
            <s:select cssStyle="width:105px" name="operator" id="operator"
            		  list="@com.lightsaber.trade.as.web.planfirst.Operator@list()" listKey="key" listValue="value" onchange="onPlanYearChange($('#level1Planning_planningExercise').val(),'category')">
            </s:select>
        </div>
      </td>      
      
    </tr>
    <tr>
      <td colspan="3">
      	<label class="fLabel">Branch Name </label>
        <div class="fField">
            <s:select cssStyle="width:525px" name="level1Planning.category.id" 
            		  list="categoryList" listKey="code" listValue="desc" id="level1PlanningCategory"
            		  headerKey="" headerValue="-- Select --">
            </s:select>
         </div>
       </td>
    </tr>
  </tbody>
  </table>
  
  
  <div class="btnSet btnSetTypeB">
    <div class="left">
      <div class="button">
        <div class="left">
          <div class="right">
            <input type="button" onclick="clickBtn('search')" value="Search" name="" id="" class="inputButton">
          </div>
        </div>
      </div>
      <div class="button">
        <div class="left">
          <div class="right">
            <input type="button" onclick="clickBtn('clear')" value="Clear" name="" id="" class="inputButton">
          </div>
        </div>
      </div>
    </div>
  </div>
  
</div>

<!-- InstanceBeginEditable name="content" -->
<s:if test="%{page!=null&&page.result!=null&&page.result.size()!=0}">
<div class="sListBorder">
  <div class="sList">
    <table cellspacing="0" cellpadding="0" border="0" width="100%" class="sTable">
      <tbody><tr>
        <td style="width:150px" class="sTh t">Planning Exercise</td>
        <td class="sTh t">Planning Exercise Name</td>
        <td class="sTh t">Branch Name</td>
        <td class="sTh t">1st Level Plan Name</td>
        <td class="sTh t">Status</td>
        <td class="sTh t">Action</td>
      </tr>
      
      <s:iterator value="page.result" var="level1Planning" status="st">
      
       	  <s:set var="trClass" value="'sRow1'"></s:set>
    	  <s:if test="#st.index%2==0">
       	 		<s:set var="trClass" value="'sRow2'"></s:set>
	       	 <s:else>
	       	    <s:set var="trClass" value="'sRow1'"></s:set>
	       	 </s:else>
		  </s:if>
		  
	      <tr class="<s:property value="#trClass"/>">
	      <td class="sCell" id="yearTD_<s:property value='#st.index' />"><s:property value="#level1Planning.planningExercise"/></td>
	        <script>
			var year = "<s:property value='#level1Planning.planningExercise' />";
			var toYear = parseInt(year) + 1;
			document.getElementById("yearTD_<s:property value='#st.index' />").innerHTML=year+"/"+toYear.toString().substring(2,4);
			</script>
	        <td class="sCell">
	        	<a href="#" onclick="clickBtn('edit','<s:property value='#level1Planning.id'/>')">
	        		<s:property value="#level1Planning.category.planningExerciseName"/>
	        	</a></td>
	        <td class="sCell"><s:property value="#level1Planning.category.branchName"/>&nbsp;</td>
	        <td class="sCell"><s:property value="#level1Planning.name"/></td>
	        <td class="sCell black b"><s:property value="#level1Planning.status.label"/></td>
	        <td class="sCell buttonCell">
	        	<s:if test="@com.lightsaber.trade.as.web.planfirst.Operator@OWNER==operator">
		        	<s:if test="#level1Planning.status.canDelelteLevel1">
			        	<div class="button sbtn">
				            <div class="left">
				              <div class="right">
				              <security:authorize access="hasRole('PLANNING_1ST_LEVEL_DELETE')">
				                <input type="button" onclick="clickBtn('delete','<s:property value='#level1Planning.id'/>')" value="<s:text name='common.btn.delete'/>" name="" id="" class="inputButton">
				              </security:authorize>
				              </div>
				            </div>
			            </div>
		            </s:if>
	            </s:if>
	            
	            &nbsp;
	         </td>
	      </tr>
      
      </s:iterator>
      
    </tbody></table>
  </div>
  
 <vtc:paging page="page"></vtc:paging>
</div>
</s:if>
<s:elseif test="%{search && (page==null||page.result==null||page.result.size()==0)}">
<div class="sListBorder">
  <div class="sList">
    <table cellspacing="0" cellpadding="0" border="0" width="100%" class="sTable">
      <tbody><tr>
        <td style="width:150px" class="sTh t">Planning Exercise</td>
        <td class="sTh t">Planning Exercise Name</td>
        <td class="sTh t">Branch Name</td>
        <td class="sTh t">1st Level Plan Name</td>
        <td class="sTh t">Status</td>
        <td class="sTh t">Action</td>
      </tr>
      <tr><td colspan="6" align="center">
      <br/>
No 1st Level Plan Record Found, Please check whether it is created or user account with access right.
  <br/>
	</td></tr>
	    </tbody></table>
  </div>
  
</div>
</s:elseif>


</s:form>
</div>

</body>
</html>